package com.yb.guigu.pick.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yb.guigu.pick.db.bean.PageRequest;
import com.yb.guigu.pick.product.entity.Category;
import com.yb.guigu.pick.product.mapper.CategoryMapper;
import com.yb.guigu.pick.product.service.ICategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yb.guigu.pick.core.bean.GuiguResult;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 商品三级分类 服务实现类
 * </p>
 *
 * @author 姚兵
 * @since 2023-06-10
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements ICategoryService {

    @Override
    public GuiguResult<?> listPage(PageRequest<Category> pageRequest) {
        String name = pageRequest.getCondition().getName();

        LambdaQueryWrapper<Category> lambdaQueryWrapper = new LambdaQueryWrapper<>();

        if(StringUtils.hasText(name)){
            lambdaQueryWrapper.like(Category::getName,name.trim());
        }

        Page<Category> page = new Page<>(pageRequest.getCurrent(), pageRequest.getSize());

        return GuiguResult.success(this.page(page,lambdaQueryWrapper));
    }
}
